let api = "..";
let tem = "..";

function jumper() {
    var page = document.getElementById("choosePage");
    if (page === null)
        return;
    var obj_lis = page.getElementsByTagName("li");
    for (var i = 0; i < obj_lis.length; i++) {
        obj_lis[i].onclick = function () {
            var index = $(this).index();
            switch (index) {
                case 0:
                    window.location.href = 'userpage.html';
                    break;
                case 2:
                    window.location.href = 'main.html';
                    break;
                case 3:
                    window.location.href = 'share.html';
                    break;
                case 4:
                    window.location.href = 'recent.html';
                    break;
                case 6:
                    window.location.href = 'recycle.html';
                    break;
            }
        }
    }
}
function themeprovider() {
    $.ajax({
        url: "../template/theme_provider_template.html",
        dataType: 'html',
        type: 'GET',
        success: function (data) {
            let div = $("<div></div>");
            div.addClass("mdui-dialog");
            div.attr('id', "dialog-docs-theme");
            div.html(data);
            let DEFAULT_PRIMARY = getCookie('docs-theme-primary') || "blue";
            let DEFAULT_ACCENT = getCookie('docs-theme-accent') || "pink";
            let DEFAULT_LAYOUT = getCookie('docs-theme-layout') || '';
            $(document.body).append(div);
            $("input[name='doc-theme-primary'][value='" + DEFAULT_PRIMARY + "']").attr("checked", true);
            $("input[name='doc-theme-accent'][value='" + DEFAULT_ACCENT + "']").attr("checked", true);
            $("input[name='doc-theme-layout'][value='" + DEFAULT_LAYOUT + "']").attr("checked", true);
        }
    })
}

function initfab(data) {
    $.ajax({
        url: "../template/fab_dial_template.html",
        dataType: 'html',
        type: 'GET',
        success: function (template) {
            let fab = Mustache.render(template, data);
            $(document.body).append(fab);
        }
    })
}
$(document).ready(function () {
    jumper();
    themeprovider();
    
    $("#logout").click(function(){
		$.post({
			url: "../api/logoff",
			data: {},
			success: function() {
				mdui.snackbar({
					message: '已经登出',
					buttonText: '返回',
					onClick: function() {
                        location.href = "login.html";
					},
					onButtonClick: function() {
                        location.href = "login.html";
					},
					onClose: function() {
                        location.href = "login.html";
					}
				});
			},
			dataType: "JSON"
		});
	});
});
